package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.mapper.WsdMealRefundsMapper;
import com.ruoyi.business.service.FuiouNotifyService;
import com.ruoyi.business.service.IWsdMealRefundsService;
import com.ruoyi.common.core.domain.dto.RefundDTO;
import com.ruoyi.common.core.domain.dto.WsdMealRefundsDTO;
import com.ruoyi.common.core.domain.entity.WsdMealRefunds;
import com.ruoyi.common.core.domain.vo.RefundAvailabilityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 请假期间的餐费退款记录表 服务实现类
 * </p>
 *
 * @author wwq
 * @since 2024-05-20
 */
@Service
public class WsdMealRefundsServiceImpl extends ServiceImpl<WsdMealRefundsMapper, WsdMealRefunds> implements IWsdMealRefundsService {


    @Autowired
    private WsdMealRefundsMapper wsdMealRefundsMapper;


    @Autowired
    private FuiouNotifyService fuiouNotifyService;

    /**
     * 查询请假期间的餐费退款记录
     *
     * @param mealRefundsId 请假期间的餐费退款记录主键
     * @return 请假期间的餐费退款记录
     */
    @Override
    public WsdMealRefunds selectWsdMealRefundsByMealRefundsId(Long mealRefundsId)
    {
        return wsdMealRefundsMapper.selectWsdMealRefundsByMealRefundsId(mealRefundsId);
    }

    /**
     * 查询请假期间的餐费退款记录列表
     *
     * @param wsdMealRefunds 请假期间的餐费退款记录
     * @return 请假期间的餐费退款记录
     */
    @Override
    public List<WsdMealRefunds> selectWsdMealRefundsList(WsdMealRefunds wsdMealRefunds) {
        wsdMealRefunds.setStatus(2);
        return wsdMealRefundsMapper.selectWsdMealRefundsList(wsdMealRefunds);
    }

    @Override
    public List<WsdMealRefundsDTO> selectWsdMealRefundsListById(Long id) {
        return wsdMealRefundsMapper.selectWsdMealRefundsListById(id);
    }

    /**
     * 新增请假期间的餐费退款记录
     *
     * @param wsdMealRefunds 请假期间的餐费退款记录
     * @return 结果
     */
    @Override
    public int insertWsdMealRefunds(WsdMealRefunds wsdMealRefunds)
    {
        return wsdMealRefundsMapper.insertWsdMealRefunds(wsdMealRefunds);
    }

    /**
     * 审核请假期间的餐费退款记录
     *
     * @param wsdMealRefunds 请假期间的餐费退款记录
     * @return 结果
     */
    @Override
    public int updateWsdMealRefunds(WsdMealRefunds wsdMealRefunds) {
        if (wsdMealRefunds.getStatus() == 0){
            WsdMealRefunds wsdMealRefunds1 = wsdMealRefundsMapper.selectWsdMealRefundsByMealRefundsId(wsdMealRefunds.getMealRefundsId());
            RefundDTO refundDTO = new RefundDTO();
            refundDTO.setMchntOrderNo(wsdMealRefunds1.getTransactionId());
            refundDTO.setTotalAmt(BigDecimal.valueOf(5));
            refundDTO.setRefundAmt(wsdMealRefunds1.getRefundAmount());
            //调用接口
            fuiouNotifyService.refund(refundDTO);
        }
        return wsdMealRefundsMapper.updateWsdMealRefunds(wsdMealRefunds);
    }

    /**
     * 批量删除请假期间的餐费退款记录
     *
     * @param mealRefundsIds 需要删除的请假期间的餐费退款记录主键
     * @return 结果
     */
    @Override
    public int deleteWsdMealRefundsByMealRefundsIds(Long[] mealRefundsIds)
    {
        return wsdMealRefundsMapper.deleteWsdMealRefundsByMealRefundsIds(mealRefundsIds);
    }

    /**
     * 删除请假期间的餐费退款记录信息
     *
     * @param mealRefundsId 请假期间的餐费退款记录主键
     * @return 结果
     */
    @Override
    public int deleteWsdMealRefundsByMealRefundsId(Long mealRefundsId)
    {
        return wsdMealRefundsMapper.deleteWsdMealRefundsByMealRefundsId(mealRefundsId);
    }

    /**
     * 根据学生id和日期查询数据
     *
     * @param studentsId
     * @param s
     * @return
     */
    @Override
    public RefundAvailabilityVO selectWsdMealRefundsByLeaveId(Long leaveId, String s) {
        return wsdMealRefundsMapper.selectWsdMealRefundsByLeaveId(leaveId,s);
    }
}
